package com.hundsun.yr.universal.p2p.bean;

import java.io.Serializable;
import java.math.BigDecimal;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;

import com.hundsun.yr.universal.library.utils.HSJSONTools;
import com.hundsun.yr.universal.library.utils.HsNumberUtils;
import com.hundsun.yr.universal.library.utils.MathUtils;
import com.hundsun.yr.universal.library.utils.SpannableStringBuilderUtils;
import com.hundsun.mobile.zwgt.R;

/**
 * @Title: SelMarkEntity.java
 * @Description: 精品对象
 * @date 2016-1-22 上午9:01:44
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com
 * @replace author:
 * @replace date:
 * @version V1.0
 */
public class SelMarkEntity  extends ResponseBean implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * 取值的key
	 */
	public static String BASEKEY="goodsList";
	/**
	 * ID信息
	 */
	public static String CRGRD_KEY = "key";
	/**
	 * 值信息
	 */
	public static String CRGRD_VALUE = "value";
	/**
	 * 保障方式 ID信息
	 */
	public static String GTDMODE_KEY = "key";
	/**
	 * 保障方式值信息
	 */
	public static String GTDMODE_VALUE = "value";
	/**
	 * 担保机构 ID信息
	 */
	public static String GTDORG_KEY = "key";
	/**
	 * 担保机构 值信息
	 */
	public static String GTDORG_VALUE = "value";
	/**
	 * 投资递增金额
	 */
	private String addMny ;
	/**
	 * 年化收益率
	 */
	private String anulIncmRate ;
	/**
	 * 可用数值 （根据投资控制类型区分是份额还是人员）
	 */
	private BigDecimal avlNum ;
	/**
	 * 信用评级
	 */
	private Object crGrd ;
	/**
	 * 销售结束时间
	 */
	private String crnEndTime;
	/**
	 * 当期数值
	 */
	private String crnGdsNum;
	/**
	 * 当期已投数值
	 */
	private String crnHasIvsmNum ;
	/**
	 * 精选标识
	 */
	private String crnSelMark ;
	/**
	 * 当期销售开始时间
	 */
	private String crnStartTime;
	/**
	 * 冻结数量
	 */
	private String freezeNum ;
	/**
	 * 商品分类
	 */
	private String gdsCL;
	/**
	 * 商品ID
	 */
	private String gdsId ;
	/**
	 * 保障方式
	 */
	private Object gtdMode ;
	/**
	 * 担保机构 (非必填)
	 */
	private Object gtdOrg ;
	/**
	 * 计息方式
	 */
	private String intMode;
	/**
	 * 投资期限
	 */
	private String ivsmTmLmt ;
	/**
	 * 投资期限类型
	 */
	private String ivsmTmLmtType ;
	/**
	 * 借款人
	 */
//	private String loaner ;
	/**
	 * 借款人id
	 */
//	private String userId ;
	/**
	 * 营销商品状态( SCALEING("2", "销售中"),SCALE_COMPLETED("3", "销售完毕");)
	 */
	private String marketGoodsStatus ;
	/**
	 * 单笔购买最大金额
	 */
	private BigDecimal maxSingleMny;
	/**
	 * 累计购买最大金额
	 */
	private BigDecimal maxTotalMny ;
	/**
	 * 营销商品ID
	 */
	private String mktGdsId ;
	/**
	 * 营销商品名称
	 */
	private String mktGdsName ;
	/**
	 * 总控额度 (根据控制类型，区分是金额还是名额）
	 */
	private BigDecimal num ;
	/**
	 * 商品详情
	 */
//	private String productBasePojo ;
	/**
	 * 还款方式
	 */
	private String refundWay ;
	/**
	 * 商品发布日期
	 */
	private String releaseDate ;
	/**
	 * 投资起点金额
	 */
	private String startMny ;
	/**
	 * 是否可转让(OK_TRANSFER("1", "允许"), NO_TRANSFER("2", "不允许");)
	 */
	private String transferFlag ;
	/**
	 * 是否新手标
	 */
	private String newerOnly ;
	
	
	public String getAddMny() {
		return addMny;
	}


	public void setAddMny(String addMny) {
		this.addMny = addMny;
	}


	public String getAnulIncmRate() {
		return anulIncmRate;
	}


	public void setAnulIncmRate(String anulIncmRate) {
		this.anulIncmRate = anulIncmRate;
	}


	public BigDecimal getAvlNum() {
		return avlNum;
	}


	public void setAvlNum(BigDecimal avlNum) {
		this.avlNum = avlNum;
	}

	public String getCrnEndTime() {
		return crnEndTime;
	}


	public void setCrnEndTime(String crnEndTime) {
		this.crnEndTime = crnEndTime;
	}


	public String getCrnGdsNum() {
		return crnGdsNum;
	}


	public void setCrnGdsNum(String crnGdsNum) {
		this.crnGdsNum = crnGdsNum;
	}


	public String getCrnHasIvsmNum() {
		return crnHasIvsmNum;
	}


	public void setCrnHasIvsmNum(String crnHasIvsmNum) {
		this.crnHasIvsmNum = crnHasIvsmNum;
	}


	public String getCrnSelMark() {
		return crnSelMark;
	}


	public void setCrnSelMark(String crnSelMark) {
		this.crnSelMark = crnSelMark;
	}


	public String getCrnStartTime() {
		return crnStartTime;
	}


	public void setCrnStartTime(String crnStartTime) {
		this.crnStartTime = crnStartTime;
	}


	public String getFreezeNum() {
		return freezeNum;
	}


	public void setFreezeNum(String freezeNum) {
		this.freezeNum = freezeNum;
	}


	public String getGdsCL() {
		return gdsCL;
	}


	public void setGdsCL(String gdsCL) {
		this.gdsCL = gdsCL;
	}


	public String getGdsId() {
		return gdsId;
	}


	public void setGdsId(String gdsId) {
		this.gdsId = gdsId;
	}


	public Object getCrGrd() {
		return crGrd;
	}


	public void setCrGrd(Object crGrd) {
		this.crGrd = crGrd;
	}


	public Object getGtdMode() {
		return gtdMode;
	}


	public void setGtdMode(Object gtdMode) {
		this.gtdMode = gtdMode;
	}


	public Object getGtdOrg() {
		return gtdOrg;
	}


	public void setGtdOrg(Object gtdOrg) {
		this.gtdOrg = gtdOrg;
	}


	public String getIntMode() {
		return intMode;
	}


	public void setIntMode(String intMode) {
		this.intMode = intMode;
	}


	public String getIvsmTmLmt() {
		return ivsmTmLmt;
	}


	public void setIvsmTmLmt(String ivsmTmLmt) {
		this.ivsmTmLmt = ivsmTmLmt;
	}


	public String getIvsmTmLmtType() {
		return ivsmTmLmtType;
	}


	public void setIvsmTmLmtType(String ivsmTmLmtType) {
		this.ivsmTmLmtType = ivsmTmLmtType;
	}




	public String getMarketGoodsStatus() {
		return marketGoodsStatus;
	}


	public void setMarketGoodsStatus(String marketGoodsStatus) {
		this.marketGoodsStatus = marketGoodsStatus;
	}




	public String getMktGdsId() {
		return mktGdsId;
	}


	public void setMktGdsId(String mktGdsId) {
		this.mktGdsId = mktGdsId;
	}


	public String getMktGdsName() {
		return mktGdsName;
	}


	public void setMktGdsName(String mktGdsName) {
		this.mktGdsName = mktGdsName;
	}


	public String getRefundWay() {
		return refundWay;
	}


	public void setRefundWay(String refundWay) {
		this.refundWay = refundWay;
	}


	public String getReleaseDate() {
		return releaseDate;
	}


	public void setReleaseDate(String releaseDate) {
		this.releaseDate = releaseDate;
	}



	public String getTransferFlag() {
		return transferFlag;
	}


	public void setTransferFlag(String transferFlag) {
		this.transferFlag = transferFlag;
	}


	public String getNewerOnly() {
		return newerOnly;
	}


	public void setNewerOnly(String newerOnly) {
		this.newerOnly = newerOnly;
	}



	/**
	 * 显示项目期限
	 */
	public String dispalyDuration(){
		
		String duration=HsNumberUtils.numberFormat("##0", ivsmTmLmt)+getLimttype(ivsmTmLmtType);
		
		return duration;
	}
	
	/**
	 * 显示项目期限
	 */
	public String dispalyLmtType(){
		return getLimttype(ivsmTmLmtType);
	}
	
	/**
	 * 显示百分比
	 */
	public String dispalyPercent(){
		return getPercent()+"%";
	}
	
	/**
	 * 显示百分比
	 */
	public String getPercent(){
		return HsNumberUtils.formartPercent(MathUtils.subtract(crnGdsNum,avlNum.toString()), crnGdsNum);
//		return HsNumberUtils.formartPercent(MathUtils.plus(freezeNum,crnHasIvsmNum), crnGdsNum);
	}
	
	
	/**
	 * 显示保障方式
	 * @return
	 */
	public String displayGtdmode(){
		String gtdKey=HSJSONTools.getString(gtdMode, SelMarkEntity.GTDMODE_KEY);
		return getgtdMode(gtdKey);
	}
	
	/**
	 * 显示进度
	 */
	public int dispalyProgress(){
		
		int progress=MathUtils.string2int(getPercent());
		return progress;
	}
	private long countTime;
	
	public long getCountTime() {
		return countTime;
	}


	public void setCountTime(long countTime) {
		this.countTime = countTime;
	}

	
	
	/**
	 * 显示年化率
	 * @param context
	 * @return
	 */
	public SpannableStringBuilder displayRate(Context context){
		String annualincome=HsNumberUtils.numberFormat("##0.00", anulIncmRate)+context.getString(R.string.percent);
		String annualincome_integer=String.valueOf((int)Math.floor(MathUtils.string2double(anulIncmRate)));
		SpannableStringBuilder spaBuilder=SpannableStringBuilderUtils.sizeAndScriptSpan(annualincome,annualincome_integer,context.getString(R.string.percent), 48);
		return spaBuilder;
	}
	
	/**
	 * 显示剩余金额
	 * @return
	 */
	public SpannableStringBuilder displayResidual(Context context){
		String residual=HsNumberUtils.tenThousandsFormat(avlNum.toString());
		String unit=HsNumberUtils.moneyUnit(avlNum.toString());
		@SuppressWarnings("deprecation")
		SpannableStringBuilder spaBuilder=(SpannableStringBuilderUtils.sizeAndColorSpan
				(context.getString(R.string._residual,residual,unit), residual,14, context.getResources().getColor(R.color.primary_cl_2),true));
		return spaBuilder;
	}
	
	/**
	 * 显示投资期限
	 * @param context
	 * @return
	 */
	public SpannableStringBuilder displayIvsmtmlmt(Context context){
		SpannableStringBuilder spaBuilder=SpannableStringBuilderUtils.sizeSpan(ivsmTmLmt+getLimttype(ivsmTmLmtType),ivsmTmLmt,30);
		return spaBuilder;
	}
	
	/**
	 * 显示起投金额
	 * @param context
	 * @return
	 */
	public SpannableStringBuilder displayStartMny(Context context){
		SpannableStringBuilder spaBuilder=SpannableStringBuilderUtils.sizeSpan(context.getString(R.string._yuan,startMny),
				startMny, 30);
		return spaBuilder;
	}
	
	
	public BigDecimal getMaxSingleMny() {
		return maxSingleMny;
	}


	public void setMaxSingleMny(BigDecimal maxSingleMny) {
		this.maxSingleMny = maxSingleMny;
	}


	public BigDecimal getMaxTotalMny() {
		return maxTotalMny;
	}


	public void setMaxTotalMny(BigDecimal maxTotalMny) {
		this.maxTotalMny = maxTotalMny;
	}


	public BigDecimal getNum() {
		return num;
	}


	public void setNum(BigDecimal num) {
		this.num = num;
	}


	public String getStartMny() {
		return startMny;
	}


	public void setStartMny(String startMny) {
		this.startMny = startMny;
	}


	/**
	 * 是否精选    精选  CHOICE("2", "精选"),  普通  ORDINARY("1", "普通");
	 * @param selMark
	 * @return
	 */
	public boolean ifSelMark(){
		
		if(TextUtils.equals(crnSelMark, "CHOICE")){
			return true;
		}else{
			return false;
		}
	}
	
	
	
	/**
	 * 保障方式
	 * @param key
	 * @return
	 */
	public static String getgtdMode(String key) {
		String value="本息保障";
		
		if(TextUtils.equals(key, "1")){
			value="本息保障";
		}else if(TextUtils.equals(key, "2")){
			value="本金保障";
		}
		
		return value;
	}
	
	
	/**
	 * 设置默认值
	 */
	public void setDefaultMark(){
		setIvsmTmLmt("0");
		setIvsmTmLmtType("DAY");
		setStartMny("0");
		setMktGdsName("敬请期待");
		setAnulIncmRate("0");
		setAvlNum(new BigDecimal("0"));
		setCrnHasIvsmNum("0");
		setGdsId("00000");
		setGtdOrg("{\"key\": \"资金由江西银行安全存管\",  \"value\": \"资金由江西银行安全存管\"}");
	}
	
	
	
	/**
	 * 产品期限
	 */
	public static final class Term {
		/**
		 * 不限
		 */
		public static String UNLIMIT = "UNLIMIT";
		/**
		 * 6个月及以下
		 */
		public static String SIX_MONTH_OR_LESS = "SIX_MONTH_OR_LESS";
		/**
		 * 7-12个月
		 */
		public static String SEVEN_TWELF_MONTH = "SEVEN_TWELF_MONTH";
		/**
		 * 13-24个月
		 */
		public static String THIRTEEN_TWENTYFOUR_MONTH = "THIRTEEN_TWENTYFOUR_MONTH";
		/**
		 * 24个月及以上
		 */
		public static String TWENTYFOUR_MONTH_OR_MORE = "TWENTYFOUR_MONTH_OR_MORE";
	}

	/**
	 * 获取投资期限单位
	 * 
	 * @param ivsmtmlmttype
	 *            投资期限类型
	 * @return String
	 */
	public static String getLimttype(String ivsmtmlmttype) {

		String limttype = "";

		if (TextUtils.equals(ivsmtmlmttype, "DAY")) {
			limttype = "天";
		} else if (TextUtils.equals(ivsmtmlmttype, "MONTH")) {
			limttype = "月";
		}

		return limttype;
	}
	
	
	/**
	 * 还款方式
	 * 
	 * @param refundWay  还款方式
	 * @return String
	 */
	public static String EnumRefundWay(String refundWay) {

		String mRefundWay = "";
		
		if (TextUtils.equals(refundWay, "ONCE_TIME")) {
			mRefundWay = "到期还本付息";
		} else if (TextUtils.equals(refundWay, "MONTH_PROFIT")) {
			mRefundWay = "按月付息到期还本";
		}else if (TextUtils.equals(refundWay, "QUARTER_PROFIT")) {
			mRefundWay = "按季付息到期还本";
		}else if (TextUtils.equals(refundWay, "HALFYEAR_PROFIT")) {
			mRefundWay = "按半年付息到期还本";
		}else if (TextUtils.equals(refundWay, "MONTH_AMT")) {
			mRefundWay = "按月等额本息";
		}else if (TextUtils.equals(refundWay, "MONTH_PRINCIPAL")) {
			mRefundWay = "按月等额本金";
		}

		return mRefundWay;
	}
	
	/**
	 * 计息方式
	 * 
	 * @param refundWay  计息方式
	 * @return String
	 */
	public static String EnumIntMode(String inMode) {

		String mInMode = "";
		
		if (TextUtils.equals(inMode, "THE_DAY_BEARING")) {
			mInMode = "当日计息";
		} else if (TextUtils.equals(inMode, "MORROW_BEARING")) {
			mInMode = "次日计息";
		}else if (TextUtils.equals(inMode, "SATISFY_BEARING")) {
			mInMode = "满标计息";
		}else if (TextUtils.equals(inMode, "ESTABLISH_BEARING")) {
			mInMode = "成立计息";
		}

		return mInMode;
	}
	

	/**
	 * 计息方式
	 * 
	 */
	public enum EnumIntMode {
		/** 当日计息 */
		THE_DAY_BEARING("1", "当日计息"),
		/** 次日计息 */
		MORROW_BEARING("2", "次日计息"),
		/** 满标计息 */
		SATISFY_BEARING("3", "满标计息"),
		/** 成立计息 */
		ESTABLISH_BEARING("4", "成立计息");

		private String code;

		private String description;

		private EnumIntMode(String code, String description) {

			this.code = code;
			this.description = description;

		}

		/**
		 * 根据结算周期代码获取结算周期枚举
		 * 
		 * @param code
		 *            结算周期代码
		 * @return 结算周期枚举实例
		 */
		public static EnumIntMode find(String code) {

			for (EnumIntMode assetAcctApplicaEnum : EnumIntMode.values()) {
				if (assetAcctApplicaEnum.getCode().equals(code)) {
					return assetAcctApplicaEnum;
				}
			}
			return null;
		}

		/**
		 * @return 结算周期代码
		 */
		public String getCode() {
			return code;
		}

		/**
		 * @return 结算周期信息
		 */
		public String getDescription() {
			return description;
		}

	}

	/**
	 * 
	 * 营销商品状态
	 * 
	 */
	public enum EnumMarketGoodsStatus {
		/** 销售中 */
		SCALEING("SCALEING", "销售中"),
		/** 销售完毕 */
		SCALE_COMPLETED("SCALE_COMPLETED", "销售完毕");

		/** 状态 */
		private String status;
		/** 状态描述 */
		private String description;

		/**
		 * 私有构造方法
		 * 
		 * @param status 状态
		 * @param description 描述
		 */
		private EnumMarketGoodsStatus(String status, String description) {
			this.status = status;
			this.description = description;
		}

		/**
		 * 根据编码查找枚举
		 * 
		 * @param code  编码
		 * @return {@link EnumMarketGoodsStatus} 实例
		 */
		public static EnumMarketGoodsStatus find(String code) {
			for (EnumMarketGoodsStatus frs : EnumMarketGoodsStatus.values()) {
				if (frs.getStatus().equals(code)) {
					return frs;
				}
			}
			return null;
			// throw new Exception("错误码", "根据code=" + code+ "获取渠道标示失败");
		}
		
		/**
	     * 根据枚举查找描述
	     * 
	     * @param status 枚举
	     * @return String
	     **/
	    public static String getDescription(String status) {
	    	for (EnumMarketGoodsStatus frs : EnumMarketGoodsStatus.values()) {
	            if (frs.status.equals(status)) {
	                return frs.description;
	            }
	        }
			return status;
	    }

		public String getStatus() {
			return status;
		}

		public String getDescription() {
			return description;
		}
	}
	
	
}
